import { computed, defineEmits } from 'vue'

export function useVModel<
    _T_Props extends Record<string, any>,
    _T_PropName extends (keyof _T_Props & string) = (keyof _T_Props & string)
> (
    props: _T_Props,
    $emit: ReturnType<typeof defineEmits>,
    propName: _T_PropName
) {
    const eventName = `update:${propName}`

    const value = computed<_T_Props[_T_PropName]>({
        get ( ) { return props[propName] },
        set (v) { $emit(eventName, v) },
    })

    return value
}
